package com.demo.service.impl;


import java.util.List;

import com.demo.entity.po.AiMessage;

import com.demo.entity.query.AiMessageQuery;

import com.demo.entity.vo.PaginationResultVO;

import com.demo.service.AiMessageService;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import com.demo.entity.query.SimplePage;

import com.demo.mappers.AiMessageMapper;

import com.demo.entity.enums.PageSize;

/**
 * @Description:AI对话消息表serviceImpl
 * @Date:2025-03-01
 * @author：author
*/
@Service("aiMessageService")
public class AiMessageServiceImpl implements AiMessageService{

	@Resource
	private AiMessageMapper<AiMessage,AiMessageQuery> aiMessageMapper;

	/**
	 * 根据条件查询列表
	 */
	public List<AiMessage> findListByParam(AiMessageQuery query) { 
		return this.aiMessageMapper.selectList(query);
	}

	/**
	 * 根据条件查询数量
	 */
	public Integer findCountByParam(AiMessageQuery query){
		return this.aiMessageMapper.selectCount(query);
	}

	/**
	 * 分页查询
	 */
	public PaginationResultVO<AiMessage> findListByPage(AiMessageQuery  query) { 
		int count = this.findCountByParam(query);
		int pageSize = query.getPageSize()==null?PageSize.SIZE15.getSize():query.getPageSize();
		SimplePage page = new SimplePage(query.getPageNo(),count,pageSize);
		query.setSimplePage(page);
		List<AiMessage> list = this.findListByParam(query);
		return new PaginationResultVO(count,page.getPageSize(),page.getPageNo(),page.getPageTotal(),list);
	}

	/**
	 * 新增
	 */
	public Integer add(AiMessage bean) { 
		return this.aiMessageMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	public Integer addBatch(List<AiMessage> listBean) { 
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.aiMessageMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增或者修改
	 */
	public Integer addOrUpdateBatch(List<AiMessage> listBean) { 
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.aiMessageMapper.insertOrUpdateBatch(listBean);
	}

	/**
	 * 根据MessageId查询
	 */
	public AiMessage getAiMessageByMessageId(Long messageId) { 
		return this.aiMessageMapper.selectByMessageId(messageId);
	}

	/**
	 * 根据MessageId更新
	 */
	public Integer updateAiMessageByMessageId(AiMessage bean, Long messageId) { 
		return this.aiMessageMapper.updateByMessageId(bean,messageId);
	}

	/**
	 * 根据MessageId删除
	 */
	public Integer deleteAiMessageByMessageId(Long messageId) { 
		return this.aiMessageMapper.deleteByMessageId(messageId);
	}
}